/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Converter;

import dao.LeiDAO;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import Bean.Lei;
import dao.EscolaDAO;
import javax.faces.convert.FacesConverter;
import javax.naming.InitialContext;

/**
 *
 * @author alexandre
 */
@FacesConverter(value = "LeiConverter")
public class LeiConverter implements Converter{

    private LeiDAO getSession() {
        try {
            return (LeiDAO) new InitialContext().lookup("java:global/SIAC4/LeiDAO");
        } catch (Exception ex) {
            throw new IllegalArgumentException(ex);
        }
    }
    
    Lei lei;
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
      LeiDAO instance = getSession();
        
        Integer id = Integer.valueOf(value);
       lei = instance.LeiID(id);
       return lei;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
       lei = (Lei)value;
        if(lei != null){
            return String.valueOf(lei.getId());
        }
        else{
            return null;
        }
    }
    
}
